﻿using RpcHelper;

using RpcManageClient;

using RpcModel;

using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{
        internal class RpcMerCollect : BasicCollect<RpcMerDAL>, IRpcMerCollect
        {
                private IRpcServerCollect _RpcServer => this.GetCollect<IRpcServerCollect>();
                private IRemoteGroupCollect _Group => this.GetCollect<IRemoteGroupCollect>();
                public RpcMer GetRpcMer(long id)
                {
                        RpcMer mer = this.BasicDAL.GetMer (id);
                        if (mer == null)
                        {
                                throw new ErrorException("rpc.mer.not.find");
                        }
                        return mer;
                }

                public void SetMer(long id, RpcMerSetParam datum)
                {
                        this.BasicDAL.SetMer (id, datum);
                        this._RpcServer.RefreshMer(id);
                }
                public void DropMer(long id)
                {
                        if (this._Group.CheckIsExists(id))
                        {
                                throw new ErrorException("rpc.mer.bind.server");
                        }
                        this.BasicDAL.DropMer (id);
                        this._RpcServer.RefreshMer(id);
                }
                public long AddMer(RpcMerDatum mer)
                {
                        return this.BasicDAL.AddMer (mer);
                }
                public RpcMer[] Query(string name, IBasicPage paging, out long count)
                {
                        return this.BasicDAL.Query (name, paging, out count);
                }

                public BasicRpcMer[] GetBasic (long[] ids)
                {
                        if (ids.Length == 0)
                        {
                                return System.Array.Empty<BasicRpcMer>();
                        }
                        return this.BasicDAL.GetBasic (ids);
                }
        }
}
